﻿import QtQuick 2.12
import QtCharts 2.3

//各电站逆变器品牌考核分/电站数量
ChartView {
    id: chart
    title: "逆变器分厂家考核分占比"
    titleColor: "white"
    antialiasing: true
    animationDuration: 1000
    animationOptions: ChartView.AllAnimations
    //!!legend
//    legend.backgroundVisible: true
//    legend.borderColor:"#1AE66B"
//    legend.color:"#1AE66B"
//    legend.showToolTips:true
//    legend.visible:true
//    legend.font.pixelSize: 15
    legend.labelColor:"white"
    legend.markerShape:Legend.MarkerShapeRectangle
    legend.alignment: Qt.AlignBottom
    //!!

    PieSeries {
        id: pieSeries
        onHovered: setExploded(slice, state);
    }
    Component.onCompleted: {
        appendPieByName("YangGuang");
        appendPieByName("HuiChuan");
        appendPieByName("KeHua");
        appendPieByName("ZhuiRi");
        setColor();
    }

    function appendPieByName(inverterName) {
        let count = query.getPlantCountByInverter(inverterName);
        let score = query.getScoreByInverter(inverterName);
        let slice = pieSeries.append(modelH.trInverterName(inverterName), score / count);
        slice.labelPosition = PieSlice.LabelOutside;
        slice.labelFont.pixelSize = 12;
        slice.label += ":" + slice.value.toFixed(2) + "%";
    }
    function setColor() {
        var colors = ["#41B0FF", "#FFC000", "#00B050","#FF0000"];
        let count = pieSeries.count;
        for(let i = 0; i < count; i++) {
            pieSeries.at(i).color = colors[i];
            pieSeries.at(i).explodeDistanceFactor = 0.15;
            pieSeries.at(i).labelColor = "white";
        }
    }
    function setExploded(slice, state) {
        slice.labelVisible = state;
        slice.exploded = state;
        console.log(slice.value);
        if (state) {
            slice.borderColor = "red";
            slice.borderWidth = 3;
        }
        else {
            slice.borderColor = "white";
            slice.borderWidth = 1;
        }
    }
}
